package com.zzh.model.singleton;

/**
 * @author zhangzhihao
 * @email zhangzhihao@gongjiangren.net
 * @date 2020-11-14
 * @desc
 */
public class SingletonDemo {


    private SingletonDemo() {
    }

    /**
     * 单利一
     * 积汉
     */

    private static final SingletonDemo singletonDemo = new SingletonDemo();

    public static SingletonDemo getInstanceOne() {
        return singletonDemo;
    }

    /**
     * 单利二
     * 懒汉
     */

    private static volatile SingletonDemo mSingletonDemo;

    public static synchronized SingletonDemo getInstanceTwo() {
        if (mSingletonDemo == null) {
            mSingletonDemo = new SingletonDemo();
        }
        return mSingletonDemo;
    }

    /**
     * 单利三
     */

    private static class SingletonDemoHolder {
        static SingletonDemo singletonDemo = new SingletonDemo();
    }

    public static SingletonDemo getInstance() {
        return SingletonDemoHolder.singletonDemo;
    }

}
